<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/static/element/index.css}"/>
</head>
<body>
<div id="app">
    <template>
        <el-card style="background-color: #f7f7f7">
            <el-form :model="queryForm" ref="queryForm" :inline="true" label-width="100px">
                <el-form-item label="用户账号" prop="userName">
                    <el-input
                            v-model="queryForm.userName"
                            placeholder="请输入用户账号"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
                <el-form-item label="登录IP地址" prop="ipaddr">
                    <el-input
                            v-model="queryForm.ipaddr"
                            placeholder="请输入登录IP地址"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
                <el-form-item label="登录地点" prop="loginLocation">
                    <el-input
                            v-model="queryForm.loginLocation"
                            placeholder="请输入登录地点"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>

                <el-form-item label="操作系统" prop="os">
                    <el-input
                            v-model="queryForm.os"
                            placeholder="请输入操作系统"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>

                <el-form-item label="提示消息" prop="msg">
                    <el-input
                            v-model="queryForm.msg"
                            placeholder="请输入提示消息"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
                <el-form-item label="访问时间" prop="loginTime">
                    <el-date-picker clearable size="small" style="width: 200px"
                                    v-model="queryForm.loginTime"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择访问时间">
                    </el-date-picker>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">清空</el-button>
                </el-form-item>
            </el-form>
        </el-card>

        <el-row style="margin-top: 1%">
            <el-col :span="1.5">
                <el-button
                        type="primary"
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAddOrUpdate(1,null)"
                        v-if="button.add"
                >
                    新增
                </el-button>
            </el-col>
        </el-row>


        <el-table
                v-loading="loading"

                :data="tableData" row-key="id"
                :header-cell-style="{'text-align':'center','color':'grey','font-weight':'600'}"
                :cell-style="{'text-align':'center'}" border style="margin-top: 10px"
        >
            <el-table-column label="编号" align="center" prop="infoId"></el-table-column>
            <el-table-column label="用户账号" align="center" prop="userName"></el-table-column>
            <el-table-column label="登录IP地址" align="center" prop="ipaddr"></el-table-column>
            <el-table-column label="登录地点" align="center" prop="loginLocation"></el-table-column>
            <el-table-column label="浏览器类型" align="center" prop="browser"></el-table-column>
            <el-table-column label="操作系统" align="center" prop="os"></el-table-column>
            <el-table-column label="提示消息" align="center" prop="msg"></el-table-column>
            <el-table-column label="访问时间" align="center" prop="loginTime"></el-table-column>

        </el-table>
        <el-pagination
                background
                :page-sizes="[10, 20, 30, 40,50]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :page-size.sync="pageSize"
                :current-page.sync="currentPage"
                @size-change="handleQuery"
                @current-change="handleQuery"
                style="float: right;margin-top: 10px"
        />
    </template>
</div>
</body>
<script th:src="@{/static/js/axios.min.js}"></script>
<script th:src="@{/static/js/request.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/api/sysLoginRecord.js}"></script>
<script th:src="@{/static/js/vue.min.js}"></script>
<script th:src="@{/static/element/index.js}"></script>
<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/layer/layer.js}"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                currentPage: 1,
                pageSize: 10,
                total: 0,
                tableData: [],
                button: {
                    add: false,
                    update: false,
                    delete: false
                },
                loading: false,
                queryForm: {
                    roleName: ''
                }
            }
        },
        created() {
            this.handleQuery();
            let sysButtons = JSON.parse(localStorage.getItem("mars-sysButtons"));
            this.button.add = sysButtons.indexOf("admin/sysLoginRecord/add") > -1;
            this.button.update = sysButtons.indexOf("admin/sysLoginRecord/update") > -1;
            this.button.delete = sysButtons.indexOf("admin/sysLoginRecord/delete") > -1;
        },
        methods: {
            resetQuery() {
                this.queryForm = {}
                this.handleQuery()
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.handleQuery();
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.handleQuery();
            },
            handleQuery() {
                let queryParam = this.queryForm
                queryParam.pageNo = this.currentPage
                queryParam.pageSize = this.pageSize
                this.loading = true
                pageList(queryParam).then((res) => {
                    if (res.code === '200') {
                        this.tableData = res.data.list;
                        this.total = res.data.count;
                        this.loading = false
                    } else {
                        this.loading = false;
                        this.$notify({
                            title: '失败',
                            message: res.message,
                            type: 'error'
                        });
                    }
                });
            },
            handleDelete(row) {
                deleteById('/admin/sysLoginRecord/delete/' + row.id, this);
            },

            handleAddOrUpdate(type, row) {
                if (type === 1) {
                    openPage('新增系统访问记录', '/system/sysLoginRecord/sysLoginRecord-add-update.html', this);
                } else {
                    openPage('修改系统访问记录', '/system/sysLoginRecord/sysLoginRecord-add-update.html?id=' + row.id, this);
                }
            },
        }
    });
</script>
</html>
